package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.GridPolicy;
import com.ruoyi.system.service.IGridPolicyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 策略管理Controller
 * 
 * @author ruoyi
 * @date 2021-12-30
 */
@RestController
@RequestMapping("/system/policy")
public class GridPolicyController extends BaseController
{
    @Autowired
    private IGridPolicyService gridPolicyService;

    /**
     * 查询策略管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:list')")
    @GetMapping("/list")
    public TableDataInfo list(GridPolicy gridPolicy)
    {
        startPage();
        List<GridPolicy> list = gridPolicyService.selectGridPolicyList(gridPolicy);
        return getDataTable(list);
    }

    /**
     * 导出策略管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:policy:export')")
    @Log(title = "策略管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, GridPolicy gridPolicy)
    {
        List<GridPolicy> list = gridPolicyService.selectGridPolicyList(gridPolicy);
        ExcelUtil<GridPolicy> util = new ExcelUtil<GridPolicy>(GridPolicy.class);
        util.exportExcel(response, list, "策略管理数据");
    }

    /**
     * 获取策略管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:policy:query')")
    @GetMapping(value = "/{policyId}")
    public AjaxResult getInfo(@PathVariable("policyId") Integer policyId)
    {
        return AjaxResult.success(gridPolicyService.selectGridPolicyByPolicyId(policyId));
    }

    /**
     * 新增策略管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:add')")
    @Log(title = "策略管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody GridPolicy gridPolicy)
    {
        return toAjax(gridPolicyService.insertGridPolicy(gridPolicy));
    }

    /**
     * 修改策略管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:edit')")
    @Log(title = "策略管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody GridPolicy gridPolicy)
    {
        return toAjax(gridPolicyService.updateGridPolicy(gridPolicy));
    }

    /**
     * 删除策略管理
     */
    @PreAuthorize("@ss.hasPermi('system:policy:remove')")
    @Log(title = "策略管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{policyIds}")
    public AjaxResult remove(@PathVariable Integer[] policyIds)
    {
        return toAjax(gridPolicyService.deleteGridPolicyByPolicyIds(policyIds));
    }
}
